解题思路:
本题是利用形参对结构体变量中的值进行修改并通过地址把函数值返回。
第一处:必须定义结构指针返回类型,所以应填:struct student *。
第二处:分别对成绩增加1分,所以应填:a->score[i]。
第三处:返回结构指针a,所以应填:a。
***************************************************
给定程序MODI1.C中函数fun的功能是:从N个字符串中找出最长的那个串,并将其地址作为函数值返回。各字符串在主函数中输入,并放入一个字符串数组中。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
给定源程序:
#include
#include
#define N 5
#define M 81
fun(char (*sq)[M])
{ int i; char *sp;
sp=sq[0];
for(i=0;i if(strlen( sp) sp=sq[i] ;
return sq;
}
main()
{ char str[N][M], *longest; int i;
printf("Enter %d lines :\n",N);
for(i=0; i printf("\nThe N string :\n",N);
for(i=0; i longest=fun(str);
printf("\nThe longest string :\n"); puts(longest);
}